home *** CD-ROM | disk | FTP | other *** search
/ The AGA Experience 3 / AGA Experience Volume 3 (1997)(NFA - SAdENESS)[!].iso / software / utilities / graphics / raylab / source / platform / amiga / platform.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-16  |  6.9 KB  |  247 lines

  1. /*
  2.     name:    platform.c
  3.  
  4.     Misc. Amiga specific code
  5.     -------------------------
  6.  
  7.  
  8.     This source-code is part of the RayLab 1.1 package, and it is provided
  9.     for your compiling pleasure.  You may use it, change it, re-compile it
  10.     etc., as long as nobody else but you receive the changes/compilations
  11.     that you have made!
  12.  
  13.     You may not use any part(s) of this source-code for your own productions
  14.     without the permission from the author of RayLab. Please read the legal
  15.     information found in the users documentation for RayLab for more details.
  16.  
  17. */
  18.  
  19.  
  20. #include  <stdlib.h>
  21. #include  <string.h>
  22. #include  <signal.h>
  23.  
  24. #include  <exec/libraries.h>        /* AmigaOS specific includes */
  25. #include  <libraries/locale.h>
  26. #include  <dos/dosextens.h>
  27.  
  28. #include  <proto/exec.h>        /* AmigaOS prototypes */
  29. #include  <proto/locale.h>
  30. #include  <proto/dos.h>
  31.  
  32. #include  "defs.h"
  33. #include  "amidefs.h"
  34. #include  "extern.h"
  35.  
  36.  
  37.  
  38. #define MIN_STACK_SIZE 40000L
  39. #define TBUF_SIZE      16
  40.  
  41. void GetLanguage(void);
  42. void BreakHandler(int SigNum);
  43. void FPErrHandler(int SigNum);
  44.  
  45.  
  46. static char *Version = "$VER: RayLab 1.1 (c)1995-1996 by Marcus Geelnard";
  47.  
  48. /*
  49.    Locale language support (requires AmigaOS 2.1 or higher)
  50.  
  51.    I chosed to keep the "catalog" inside the source-code, so that
  52.    external modules are not needed... Will perhaps change this(?)
  53.    It was only for fun, really, anyway. Feel free to add any language
  54.    of your choise.
  55. */
  56.  
  57.     char *MyCatalog_eng[] = {
  58.         "RayLab 1.1 Display",
  59.         "RayLab - Chose display type",
  60.         " 0 - No display [default]\n",
  61.         " 1 - Select from requester\n",
  62.         " 2 - Grey (16 colors)    Hires Interlaced\n",
  63.         " 3 - HAM6 (4096 colors)  Lores\n",
  64.         " 4 - HAM6 (4096 colors)  Lores Interlaced\n",
  65.         " 5 - HAM8 (16M colors)   Lores\n",
  66.         " 6 - HAM8 (16M colors)   Lores Interlaced\n",
  67.         " 7 - HAM8 (16M colors)   Hires\n",
  68.         " 8 - HAM8 (16M colors)   Hires Interlaced\n",
  69.         "Warning: Could not open intuition.library (v36+); no display possible\n\n",
  70.         "Warning: Could not open graphics.library (v36+); no display possible\n\n",
  71.         "Warning: Unsupported display type (%ld), no display opened\n\n",
  72.         "\n*** RayLab was interrupted. Closing down...\n",
  73.         "\n*** Floating point error. Closing down...\n",
  74.         "Warning: Could not open display window\n\n",
  75.         "Warning: Could not open display screen\n\n",
  76.         "Warning: True-color displays not yet supported\n\n",
  77.         "Menu",
  78.         " About",
  79.         " Close",
  80.         "Available display-modes:\n-----------------------\n\n",
  81.         "CON:10/50/620/140/RayLab 1.1 output window",
  82.         "Error: Stack is too small! Use at least %ld bytes for stack\n",
  83.         "\n** Press return to exit RayLab **"
  84.     };
  85.  
  86.     char *MyCatalog_sve[] = {
  87.         "RayLab 1.1 Bildskärm",
  88.         "RayLab - Välj skärmläge",
  89.         " 0 - Ingen bildskärm [standard]\n",
  90.         " 1 - Välj skärmläge med dialogruta\n",
  91.         " 2 - Grå  (16 färger)    Högupplösning Interlace\n",
  92.         " 3 - HAM6 (4096 färger)  Lågupplösning\n",
  93.         " 4 - HAM6 (4096 färger)  Lågupplösning Interlace\n",
  94.         " 5 - HAM8 (16M färger)   Lågupplösning\n",
  95.         " 6 - HAM8 (16M färger)   Lågupplösning Interlace\n",
  96.         " 7 - HAM8 (16M färger)   Högupplösning\n",
  97.         " 8 - HAM8 (16M färger)   Högupplösning Interlace\n",
  98.         "Varning: Kunde inte öppna intuition.library (v36+); ingen bildskärm möjlig\n\n",
  99.         "Varning: Kunde inte öppna graphics.library (v36+); ingen bildskärm möjlig\n\n",
  100.         "Varning: Bildskärms-typ ej understödd (%ld), ingen bildskärm öppnad\n\n",
  101.         "\n*** RayLab blev avbruten. Stänger ned...\n",
  102.         "\n*** Flyttals fel. Stänger ned...\n",
  103.         "Varning: Kunde inte öppna bildskärms-fönster\n\n",
  104.         "Varning: Kunde inte öppna bildskärm\n\n",
  105.         "Varning: Fullfärgs skärmar stöds ej av RayLab än\n\n",
  106.         "Meny",
  107.         " Om",
  108.         " Stäng",
  109.         "Tillgängliga bildskärms-lägen:\n------------------------------\n\n",
  110.         "CON:10/50/620/140/RayLab 1.1 utskrifts fönster",
  111.         "Fel: Stacken är för liten! Använd minst %ld byte stack\n",
  112.         "\n** Tryck på vagn-retur för att avsluta RayLab **"
  113.     };
  114.  
  115.     char **MyCatalogs[] = {
  116.         MyCatalog_eng,
  117.         MyCatalog_sve
  118.     };
  119.  
  120.  
  121. /* Some global variables */
  122.  
  123.     struct LocaleBase *LocaleBase = NULL;
  124.     struct Library *DosBase = NULL;
  125.     int    Language = LANG_ENGLISH;
  126.     int    FromCLI = TRUE;
  127.     char    *TextBuffer = NULL;
  128.  
  129. /******************************************************************
  130.  *
  131.  *  InitPlatform()
  132.  *
  133.  ******************************************************************/
  134.  
  135. void InitPlatform(void)
  136. {
  137.     struct Process *MyProc;
  138.  
  139.     /* Determine locale language, if possible */
  140.     GetLanguage();
  141.  
  142.  
  143.     /* Determine some things about our process */
  144.     MyProc = (struct Process *)FindTask(NULL);
  145.     if((MyProc->pr_CLI) != NULL) FromCLI = TRUE;
  146.     else FromCLI = FALSE;
  147.     if(FromCLI == TRUE) {
  148.         textoutput = stderr;
  149.     }
  150.     else {
  151.         textoutput = fopen(MyCatalogs[Language][CTXT_WINNAME],"w+");
  152.     }
  153.  
  154.     /* Reduce text output stream buffer-size (for libnix) */
  155.     TextBuffer = malloc((size_t)TBUF_SIZE);
  156.     if(TextBuffer != NULL) {
  157.         fflush(textoutput);
  158.         setvbuf(textoutput,TextBuffer,_IOFBF,TBUF_SIZE);
  159.     }
  160.  
  161.     if(((MyProc->pr_Task.tc_SPUpper - MyProc->pr_Task.tc_SPLower) + 4) < MIN_STACK_SIZE) {
  162.         fprintf(textoutput,MyCatalogs[Language][CTXT_STACK],MIN_STACK_SIZE);
  163.         cleanup();
  164.         exit(1);
  165.     }
  166.  
  167.  
  168.     /* Install break-handlers */
  169.     (void) signal(SIGINT, (void *)BreakHandler);
  170.     (void) signal(SIGTERM, (void *)BreakHandler);
  171.     (void) signal(SIGFPE, (void *)FPErrHandler);
  172. }
  173.  
  174.  
  175. /******************************************************************
  176.  *
  177.  *  CloseDownPlatform()
  178.  *
  179.  ******************************************************************/
  180.  
  181. void CloseDownPlatform(void)
  182. {
  183.     if(FromCLI == FALSE) {
  184.         fprintf(textoutput,MyCatalogs[Language][CTXT_EXIT]);
  185.         (void)fgetc(textoutput);
  186.         fclose(textoutput);
  187.     }
  188.     if(TextBuffer != NULL) {
  189.         fflush(textoutput);
  190.         setvbuf(textoutput,NULL,_IONBF,NULL);
  191.         free(TextBuffer);
  192.         TextBuffer = NULL;
  193.     }
  194. }
  195.  
  196.  
  197. /***************************************************************
  198.  *
  199.  *    GetLanguage() (yes! for localization under WB 2.1+)
  200.  *
  201.  ***************************************************************/
  202.  
  203. void GetLanguage(void)
  204. {
  205.     struct Locale *loc;
  206.  
  207.     Language = LANG_ENGLISH;    /* Default */
  208.  
  209.     LocaleBase = (struct LocaleBase *)OpenLibrary("locale.library",38L);
  210.     if(LocaleBase!=NULL) {
  211.         loc = OpenLocale(NULL);
  212.         if(loc!=NULL) {
  213.         if(strcmp(loc->loc_LanguageName,"english.language")==0)
  214.             Language = LANG_ENGLISH;
  215.         else if(strcmp(loc->loc_LanguageName,"svenska.language")==0)
  216.             Language = LANG_SVENSKA;
  217.         }
  218.         CloseLibrary((struct Library *)LocaleBase);
  219.     }
  220. }
  221.  
  222.  
  223. /******************************************************************
  224.  
  225.     Interrupt handlers
  226.  
  227.  ******************************************************************/
  228.  
  229. /* This routine is called if CTRL-C is issued */
  230.  
  231. void BreakHandler(int SigNum)
  232. {
  233.     fprintf(textoutput,MyCatalogs[Language][CTXT_CTRLC]);
  234.     cleanup();
  235.     exit(1);        /* Exit RayLab after this */
  236. }
  237.  
  238. /* This routine is called in the case of a floating point error */
  239.  
  240. void FPErrHandler(int SigNum)
  241. {
  242.     fprintf(textoutput,MyCatalogs[Language][CTXT_FPERR]);
  243.     cleanup();
  244.     exit(1);        /* Exit RayLab after this */
  245. }
  246.  
  247.